<template>
<view>
<!--pages/serviceSubmit/serviceSubmit.wxml  -->

<view class="container">
  <view class="good" v-for="(item, index) in list" :key="index">
    <image class="good-img" :src="item.goods_img"></image>
    <view class="good-right">
      <view class="good-right-name">{{item.goods_name}}</view>
      <view class="good-right-sku">{{item.sku_json_info.name?item.sku_json_info.name:''}}</view>
      <view class="good-right-price">￥{{item.price}} x{{item.num}}</view>
    </view>
  </view>
  <view class="reason">
    <view class="reason-title">{{type == 2?'退款原因':"换货原因"}}</view>
	<textarea maxlength="100" :placeholder="type == 2?'请输入退款原因......':'请输入换货原因......'" v-model="reason"
		class="reason-txt" :always-embed="true" placeholder-class="pl" cursor-spacing="0"></textarea>
  </view>
  <view class="address-wrap" v-if="type == 3">
    <view class="addressImg">
      <image src="/static/images/address-1.png"></image>
    </view>
    <text>{{address}}</text>
  </view>
  <view class="btn" @tap="commit">提交</view>
</view>
</view>
</template>

<script>
// pages/serviceUpdateReason/serviceUpdateReason.js
const app = getApp().globalData;

export default {
  data() {
    return {
      type: "",
      id: "",
      info: "",
      address: "",
      reason: ""
    };
  },
  onLoad: function (options) {
    var that = this;
    var type = options.type;
    var id = options.id;
    that.setData({
      type,
      id
    });
    that.getInfo(id);
  },
  methods: {
    /**
     * 获取原因接口
     */
    getInfo(id) {
      var that = this;
      getApp().globalData.sendRequest({
        url: "/Customer/reasonInfo",
        type: "post",
        data: {
          id
        },
        success: function (res) {
          if (res.status == 1) {
            that.setData({
              info: res.reason,
              address: res.user_address,
			  reason: res.reason.apply_reason
            });
          } else {
            uni.showToast({
              title: res.msg,
              icon: 'none'
            });
          }
        }
      });
    },

    /**
     * 输入原因
     */
    inputReason(e) {
      var that = this;
      var reason = e.detail.value;
      that.setData({
        reason
      });
    },

    /**
     * 提交申请
     * 
     */
    commit() {
      var that = this;

      if (that.reason) {
        getApp().globalData.sendRequest({
          url: "/Customer/modifyReason",
          type: "post",
          data: {
            id: that.id,
            apply_reason: that.reason
          },
          success: function (res) {
            if (res.status == 1) {
              uni.showToast({
                title: res.msg
              });
              setTimeout(() => {
                uni.navigateBack();
              }, 1500);
            } else {
              uni.showToast({
                title: res.msg,
                icon: 'none'
              });
            }
          }
        });
      } else {
        uni.showToast({
          title: `请填写${that.type == 2 ? '退款' : '换货'}原因`,
          icon: 'none'
        });
      }
    }

  }
};
</script>
<style>
@import "./serviceUpdateReason.css";
</style>